﻿@using ZDSoft.LMS.Web.Apps
@model PageList<ZDSoft.LMS.Domain.User>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/Style/ViewPage.css")" rel="stylesheet" type="text/css" />
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; background-color: White;"
    align="center">
    <tr>
        <td class="mbg">
            <table cellspacing="0" cellpadding="0" width="100%" border="0" valign="top">
                <tr>
                    <td>
                        <table style="height: 23px;" cellspacing="0" cellpadding="0" width="120" background="@Url.Content("~/Content/Images/m_17.gif")"
                            border="0">
                            <tr>
                                <td>
                                    <span class="contentPageTitle">&nbsp;&gt;&gt; 员工列表</span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="titleContentDivider" height="6">
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<p>
    @Html.ActionLink("创建新用户", "Create")
</p>
@using (Html.BeginForm())
{   
    <p>
        用户名: @Html.TextBox("userName")
        <input type="submit" value="查询" class="btn3" /></p>
}
<table cellpadding="0" cellspacing="0" class="dataGrid">
    <tr>
        <th>
            用户名
        </th>
        <th>
            帐户名
        </th>
        <th>
            状态
        </th>
        <th>
            角色
        </th>
        <th>
            操作
        </th>
    </tr>
        @if (Model == null || Model.Count() == 0)
        { 
        <td colspan="5">没有满足条件的数据！</td>
        }
        else
        {
            foreach (var item in Model)
            {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Account)
            </td>
            <td>
                @Html.CheckBoxFor(modelItem => item.IsActive)
            </td>
            <td>
                @if (item.Roles == null || item.Roles.Count == 0)
                { 
                    <span>没有配置</span>
                }
                else
                {
                    var roleCount = item.Roles.Count;
                    for (int i = 0; i < item.Roles.Count; i++)
                    {
                        var role = item.Roles[i];
                        @Html.ActionLink(role.RoleName, "Details/" + role.ID, "Role");
                        if (roleCount != (i + 1))
                        {                        
                        <span>,</span>   
                        }
                    }
                }
         
            </td>
            <td> 
                @Html.ActionLink("配制角色", "AssignRole", new { id = item.ID }) |              
                @Html.ActionLink("详细信息", "Details", new { id = item.ID }) |
                @if (item.IsActive)
                {
                    if (item.Account.ToLower().Trim() != "admin" && item.Account.ToLower().Trim() != AppHelper.LoginedUser.Account)
                    {
                     @Html.ActionLink("注销","SwitchStatus","User",new{id=item.ID.ToString()},new{}) @:|
                    }
                    else{
                        @:<span style="color:Gray">注销</span> |
                    }
                 
                }
                else
                {
                    @Html.ActionLink("激活", "SwitchStatus", new { id = item.ID }, new { onclick = "return confirm('真的打算激活吗?')" });@: |
                }  
                @Html.ActionLink("修改", "Edit", new { id = item.ID }) 
                @if (item.Roles != null && item.Roles.Count > 0)
                { 
                    @:| <span style="color:Gray">删除</span>
                }
                else
                {
                    if (item.Account.ToLower() != "admin")
                    {
                        @:| @Html.ActionLink("删除", "Delete", new { id = item.ID })
                    }
                    else
                    {
                        @:| <span style="color:Gray">删除</span>
                    }
                }
            </td>
        </tr>
            }
        }
</table>
<div class="pager">
    @Html.Raw(Html.Pager(Model.PageIndex, Model.PageSize, Model.TotalCount, Model.PageIndex))
</div>
